package com.evaluation.util;

import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import cn.hutool.core.util.ReflectUtil;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class ClsUtil {

	public static <T> T newInstance( Class<T> clazz ) {
		T tlz;
		try {
			tlz = clazz.getDeclaredConstructor().newInstance();
		} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
				| InvocationTargetException | NoSuchMethodException | SecurityException e) {
			log.error( "异常:" + e.getMessage(), e );
			return null;
		}
		
		return tlz;
	}
	
	public static <T, C extends Annotation> void execAnnotationMethod( T bean, Class<C> annotationClass ) {
		Method[] methods = bean.getClass().getMethods();
		for (Method method : methods) {
			Annotation annotation = method.getAnnotation( annotationClass );
			if( annotation != null ) {
				ReflectUtil.invoke(bean, method);
			}
		}
	}
}
